//
//  EvaluationListViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/30.
//

import UIKit
import CollectionKit

class EvaluationListViewController: UIViewController {

  var collectionView = CollectionView()

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    setupTreeView()

    bindingObserver()
  }

  
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension EvaluationListViewController {

  func setupTreeView() {

    opacityNavigationBar()

    view.backgroundColor = .designKit.secondaryBackground
    view.addSubview(collectionView)

    collectionView.snp.makeConstraints { maker in
      maker.edges.equalToSuperview()
    }
  }

  func bindingObserver() {

    title = "评价列表"

    let selectDataSource = ArrayDataSource<String>(data:[
      "", "", ""
    ])

    let selectViewSource = ClosureViewSource<String, EvaluationCollectContentView> { data, index in
      return R.nib.evaluationCollectContentView(owner: nil)!
    } viewUpdater: { item, data, index in

    }

    let selectSizeSource = { (index: Int, data: String, size: CGSize) in
        return CGSize(width: (size.width - 15) / 2, height: 80)
    }

    let selectProvider = BasicProvider<String, EvaluationCollectContentView>(
      dataSource: selectDataSource,
      viewSource: selectViewSource,
      sizeSource: selectSizeSource,
      layout: FlowLayout(lineSpacing: 15, interitemSpacing: 10)
    )

    selectProvider.tapHandler = { (context) in

    }

    let dataSource = ArrayDataSource<String>(data:[
      "","","","","","",""
    ])

    let viewSource = ClosureViewSource<String, EvaluationItemContentView> { data, index in
      return R.nib.evaluationItemContentView(owner: nil)!
    } viewUpdater: { item, data, index in

    }

    let sizeSource = { (index: Int, data: String, size: CGSize) in
        return CGSize(width: size.width, height: 130)
    }

    let itemProvider = BasicProvider<String, EvaluationItemContentView>(
      dataSource: dataSource,
      viewSource: viewSource,
      sizeSource: sizeSource,
      layout: FlowLayout(spacing: 10, justifyContent: .spaceAround)
    )

    itemProvider.tapHandler = { (context) in

    }

    let inset = UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15)
    collectionView.provider = ComposedProvider(
        layout: FlowLayout(lineSpacing: 10).inset(by: inset),
        sections: [selectProvider, itemProvider]
    )
  }
}
